import {useEffect, useState} from 'react';

import {UserModel, UserWithCardNumber} from '../db/models/userModel';

export function useAccounts() {
  const [loading, setLoading] = useState<boolean>(true);
  const [users, setUsers] = useState<UserWithCardNumber[]>([]);

  useEffect(() => {
    const getUsers = async () => {
      setLoading(true);
      try {
        const userMoel = new UserModel();
        const result = await userMoel.getAllWithCardNumber();
        setUsers(result);
      } catch (error) {}
      setLoading(false);
    };

    getUsers();
  }, []);

  return {
    loading,
    users,
  };
}
